/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Chatree Siangklom
 * Created On : Jan 15, 2013  6:05:46 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : jpa.service.promis.common
 * File Name : SyncAttachFilesServices.java
 * TODO
 */
package jpa.service.promis.common;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import jpa.service.common.JPAService;

/**
 * @author chatree
 *
 */
public class SyncAttachFilesServices extends JPAService {

	/**
	 * @param em
	 */
	public SyncAttachFilesServices(EntityManager em) {
		super(em);
		// TODO Auto-generated constructor stub
	}
	
	
	public String GetAttachFile(String module, String company, String project, String type, String series, String number, String revision) throws Exception {
		EntityTransaction t = null;
		try{
			t = super.getEm().getTransaction();
	        t.begin();
	        
        	Query query = super.getEm().createNativeQuery("SELECT SPL.GET_ATTACH_DOCUMENT_FILES(?1,?2,?3,?4,?5,?6,?7) FROM DUAL ");
        	query.setParameter(1, module);		System.out.println("module : " + module);
        	query.setParameter(2, company);		System.out.println("company : " + company);
        	query.setParameter(3, project);		System.out.println("project : " + project);
        	query.setParameter(4, type);		System.out.println("type : " + type);
        	query.setParameter(5, series);		System.out.println("series : " + series);
        	query.setParameter(6, number);		System.out.println("number : " + number);
        	query.setParameter(7, revision);	System.out.println("revision : " + revision);
        	
        	String  result = (String)query.getSingleResult();
        	t.commit();
        	
        	return result;
        	
		}finally {
			  if (t.isActive()) 
				  t.rollback();
	    }
	}

}
